package com.sinaapp.zhangziyou.action;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sinaapp.zhangziyou.pojo.UserEntity;
import com.sinaapp.zhangziyou.service.UCenterService;

@Controller
public class RegisterController {

	private static Logger logger = LoggerFactory
			.getLogger(RegisterController.class);

	@Autowired
	private UCenterService uCenterService;

	@RequestMapping(value = "/register")
	public String register(Model model) {

		return "register";
	}

	@RequestMapping(value = "/checkUserName")
	@ResponseBody
	public ModelAndView checkUserName(Model model, String userName) {
		boolean status = uCenterService.checkUserNameIsExist(userName);
		
		return new ModelAndView("jsonView","status",status);
	}

	@RequestMapping(value = "/checkEmail")
	@ResponseBody
	public boolean checkEmail(Model model, String email) {
		return uCenterService.checkEmailIsExist(email);
	}

	@RequestMapping(value = "/regist")
	public String regist(Model model, UserEntity userEntity) {
		Map status = uCenterService.regist(userEntity);
		if (status.size() > 0) {
			model.addAttribute("situation", status);
		}
		return "login";
	}
}
